package com.silong.util;

import java.math.BigDecimal;

/**
 * Created by zz on 2016/8/27.
 */
public class MathUtil {

    /**
     * 两数相乘返回long类型结果
     * @param d1
     * @param d2
     * @return
     */
    public static long mulToLong(double d1, double d2) {
        BigDecimal b1 = new BigDecimal(Double.toString(d1));
        BigDecimal b2 = new BigDecimal(Double.toString(d2));
        return b1.multiply(b2).longValue();
    }


    /**
     * 两数相乘返回int类型结果
     * @param d1
     * @param d2
     * @return
     */
    public static int mulToInt(double d1, double d2) {
        BigDecimal b1 = new BigDecimal(Double.toString(d1));
        BigDecimal b2 = new BigDecimal(Double.toString(d2));
        return b1.multiply(b2).intValue();
    }


    /**
     * 两数相乘返回double类型结果
     * @param d1
     * @param d2
     * @return
     */
    public static double mulToDouble(double d1, double d2) {
        BigDecimal b1 = new BigDecimal(Double.toString(d1));
        BigDecimal b2 = new BigDecimal(Double.toString(d2));
        return b1.multiply(b2).doubleValue();
    }


    public static void main(String[] args) {

        long a = MathUtil.mulToLong(19.09d, 100);
        System.out.println(a);

        int b = MathUtil.mulToInt(19.09d, 100);
        System.out.println(b);

        double c = MathUtil.mulToDouble(19.109d, 100);
        System.out.println(c);
    }

}
